package com.loongtech.bi.action.system;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.loongtech.bi.entity.system.EntitySystemLog;
import com.loongtech.bi.manager.system.SysLogManager;
import com.loongtech.bi.support.Session;
import com.loongtech.core.util.Time;

/**
 * 日志管理
 */
@Controller("sysLogAction")
@Scope("view")
public class SysLogAction {
	@Autowired
	private Session session;
	@Autowired
	private SysLogManager sysLogManager;
	
	private SysLogBean input; // 查询类
	private List<EntitySystemLog> logList; // 查询结果

	@Autowired
	public void init() {
		input = new SysLogBean();
		logList = new ArrayList<EntitySystemLog>();
	}

	public void search() {
		logList.clear();
		logList.addAll(sysLogManager.search(input));
		sysLogManager.addLog(session.getUserName(), "进行操作日志查询" + input);
	}
	
	public String formatTime(java.util.Date time) {
		return null != time ? Time.SDF_ALL.format(time) : "";
	}

	public List<EntitySystemLog> getLogList() {
		return logList;
	}

	public void setLogList(List<EntitySystemLog> logList) {
		this.logList = logList;
	}

	public SysLogBean getInput() {
		return input;
	}

	public void setInput(SysLogBean input) {
		this.input = input;
	}
	
	public class SysLogBean {
		private String operator; // 操作者
		private Date time = Time.currentDate(); // 日志时间
		
		private Date startTime = new Date(Time.getBeginningOfDay(-1)); // 查询条件-开始时间
		private String keyword;  // 查询条件-关键字

		@Override
		public String toString() {
			StringBuilder sb = new StringBuilder();
			sb.append("SysLogBean [operator=").append(operator == null ? "" : operator);
			sb.append(", time=").append(null != time ? Time.SDF_ALL.format(time) : "").append("]");
			
			return sb.toString();
		}
		
		public String getOperator() {
			return operator;
		}

		public void setOperator(String operator) {
			this.operator = operator;
		}

		public Date getTime() {
			return time;
		}

		public void setTime(Date time) {
			this.time = time;
		}

		public Date getStartTime() {
			return startTime;
		}

		public void setStartTime(Date startTime) {
			this.startTime = startTime;
		}

		public String getKeyword() {
			return keyword;
		}

		public void setKeyword(String keyword) {
			this.keyword = keyword;
		}
	}
}
